package org.example.dao;


import jakarta.transaction.Transactional;
import org.example.entity.Cart;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ICartRepository extends JpaRepository<Cart, Integer> {
    Cart findByUserIdAndBusinessIdAndFoodId(String userId, Integer businessId, Integer foodId);
//    public List<Cart> findAll(); 这个不用写
//    public Cart save(Cart cart);

    @Modifying
    @Query("update Cart c " + //这里这个标红,但是不影响运行
            "set c.quantity=?4 "
            + "where c.userId=?1 and c.foodId=?2 and c.businessId=?3 "
    )
    public void updateQuantityByBidAndUidAndFid(String userId, Integer foodId, Integer bussinessId, Integer quantity);

    public List<Cart> findAllByUserId(String userId);
    public List<Cart> findAllByUserIdAndBusinessId(String userId, Integer businessId);

    @Transactional
    public void deleteByUserIdAndBusinessIdAndFoodId(String userId, Integer businessId, Integer foodId);


    @Transactional
    public void deleteAllByUserIdAndBusinessId(String userId, Integer businessId);

}
